/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */

using System;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace TFrameWork.Module.ActionEditor
{

    internal partial class ActionEditor
    {
        /// <summary>
        /// 当前选中的对象
        /// </summary>
        public TrackItemStyleBase currentSelected;

        public void ShowTrackItemOnInspecotr(TrackItemStyleBase trackItem)
        {
            ActionEditorInspector.SetTrackItem(trackItem);
            Selection.activeObject = this;
        }


        #region 右键选中对象

        private bool isSelectObj = false;

        public Object selectedObject;
        private Action<Object> _selectCallBack;

        public void GetObjectPickerObjectGUI()
        {
            if (isSelectObj)
            {
                GetObjectPicker();
            }
        }
        
        private void GetObjectPicker()
        {
            Event currentEvent = Event.current;
            int objectID = EditorGUIUtility.GetObjectPickerControlID();

            if (currentEvent.commandName == "ObjectSelectorClosed" &&
                EditorGUIUtility.GetObjectPickerControlID() == objectID)
            {
                selectedObject = EditorGUIUtility.GetObjectPickerObject();
                isSelectObj = false;
                _selectCallBack?.Invoke(selectedObject);
            }
        }

        public void OpenObjectPicker<T>(string searchFilter, Action<Object> selectCallback) where T : Object
        {
            int objectID = EditorGUIUtility.GetObjectPickerControlID();
            EditorGUIUtility.ShowObjectPicker<T>(null, false, searchFilter, objectID);
            isSelectObj = true;
            _selectCallBack = selectCallback;
        }

        #endregion

    }
}
